import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import javax.swing.JTextField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import java.awt.EventQueue;
import java.awt.Font;

public class NMMWindowMichaelWorking extends JFrame implements MouseListener, MouseMotionListener  {

	
	
	private JFrame frame;
	private JPanel panel_1;
	
	  private int origX;
	  private int origY;
	  private boolean drag = false; 
      JLabel piece[] = new JLabel[24];
      JLabel red[] = new JLabel[9];
      JLabel blue[] = new JLabel[9];
      private int count = 0;
  	  JTextArea moves = new JTextArea("00");
  	  JLabel label3 = new JLabel("Moves");
  	  int board[][] = new int[7][7];
  	  int isblue = 1; 						//blue is first
      int ci = 1;
      //current position
  	  int Ex = 0;
  	  int Ey = 0;
  	  int ri = -1;
  	  int bi = -1;
  	  int totalSum;
  	  int a, b;
  	  boolean isMill = false;
  	  boolean blueTurn =true;
  	  boolean placingPiece = false;
  	  boolean movingPiece = false;
  	  JLabel movingLabel = new JLabel();
  	  JLabel newMovingLabel = new JLabel();
  	  boolean freeMoving = false;
  	  boolean bmills[] = new boolean[16];
  	  boolean rmills[] = new boolean[16];
  	 // movingLabel.setIcon(null);
  	  int toRemove = 0;
		int redCount=9;
		int blueCount=9;
		LeaderBoard leaderBoard;
		boolean flying = false;
  	  
  	  
  	  
  	  private Player player1;
  	  private Player player2;
  	  
		private final ImageIcon redcircle=new ImageIcon("redcircle.png");
		private final ImageIcon bluecircle=new ImageIcon("bluecircle.png");

  	  //TODO: figure out where the players are going to input their names...
  	  
  	  
  	  JLabel text = new JLabel("Blue First");

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {	
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NMMWindowMichaelWorking window = new NMMWindowMichaelWorking();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public NMMWindowMichaelWorking() {
		getNames();
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 703, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.NORTH);
		frame.setTitle("NineMensMorris"); //setTitle
		
		JButton btnNewGame = new JButton("New Game");
		btnNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("New Game was clicked.");
				if(JOptionPane.showConfirmDialog(null,"Do you want to start a new game","New", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
					System.out.println("New Game was clicked.");
					frame.dispose();
					NMMWindowMichaelWorking window = new NMMWindowMichaelWorking();
					window.frame.setVisible(true);
					count=0;//
					moves.setText("00");//
				}
			}
				
		});
		panel.add(btnNewGame);
		
		JButton btnRules = new JButton("Rules");
		
		btnRules.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Rules rule = new Rules();	
				
			}
		});
		panel.add(btnRules);
		
		JButton btnLeaderBoard = new JButton("Leader Board");
		leaderBoard = new LeaderBoard();
		btnLeaderBoard.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				leaderBoard.setVisible(true);
			}
		});
		panel.add(btnLeaderBoard);
		
		JButton btnQuit = new JButton("Quit");
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(JOptionPane.showConfirmDialog(null,"Are you sure that you want to quit the game","Quit", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){	
				     System.exit(0);
				}
			}
		});
		panel.add(btnQuit);
		
		panel_1 = new JPanel();
		frame.getContentPane().add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(null);
		
		JPanel panel2 = new JPanel();//
		frame.getContentPane().add(panel2, BorderLayout.SOUTH);//
		 
		moves.setFont(new Font("h",20,20));//
		panel2.add(label3);//
		panel2.add(moves);//
		
		text.setBounds(0,215,40,20);
		
		addPieces();
		
		red[0] = new JLabel(redcircle);
		red[0].setBounds(21, 22, 30, 30);
		panel_1.add(red[0]);
		
		red[1] = new JLabel(redcircle);
		red[1].setBounds(21, 60, 30, 30);
		panel_1.add(red[1]);
		
		red[2] = new JLabel(redcircle);
		red[2].setBounds(21, 98, 30, 30);
		panel_1.add(red[2]);
		
		red[3] = new JLabel(redcircle);
		red[3].setBounds(21, 136, 30, 30);
		panel_1.add(red[3]);
		
		red[4] = new JLabel(redcircle);
		red[4].setBounds(21, 174, 30, 30);
		panel_1.add(red[4]);
		
		red[5] = new JLabel(redcircle);
		red[5].setBounds(21, 212, 30, 30);
		panel_1.add(red[5]);
		
		red[6] = new JLabel(redcircle);
		red[6].setBounds(21, 250, 30, 30);
		panel_1.add(red[6]);
		
		red[7] = new JLabel(redcircle);
		red[7].setBounds(21, 288, 30, 30);
		panel_1.add(red[7]);
		
		red[8] = new JLabel(redcircle);
		red[8].setBounds(21, 326, 30, 30);
		panel_1.add(red[8]);
		
		blue[0] = new JLabel(bluecircle);
		blue[0].setBounds(636, 22, 30, 30);
		panel_1.add(blue[0]);
		
		blue[1] = new JLabel(bluecircle);
		blue[1].setBounds(636, 60, 30, 30);
		panel_1.add(blue[1]);
		
		blue[2] = new JLabel(bluecircle);
		blue[2].setBounds(636, 98, 30, 30);
		panel_1.add(blue[2]);
		
		blue[3] = new JLabel(bluecircle);
		blue[3].setBounds(636, 136, 30, 30);
		panel_1.add(blue[3]);
		
		blue[4] = new JLabel(bluecircle);
		blue[4].setBounds(636, 174, 30, 30);
		panel_1.add(blue[4]);
		
		blue[5] = new JLabel(bluecircle);
		blue[5].setBounds(636, 212, 30, 30);
		panel_1.add(blue[5]);
		
		blue[6] = new JLabel(bluecircle);
		blue[6].setBounds(636, 250, 30, 30);
		panel_1.add(blue[6]);
		
		blue[7] = new JLabel(bluecircle);
		blue[7].setBounds(636, 288, 30, 30);
		panel_1.add(blue[7]);
		
		blue[8] = new JLabel(bluecircle);
		blue[8].setBounds(636, 326, 30, 30);
		panel_1.add(blue[8]);
		
		ImageIcon boardImage=new ImageIcon("board.gif");
		
		JLabel boardholder = new JLabel(boardImage);
		boardholder.setBounds(126, 11, 435, 435);
		panel_1.add(boardholder);
		
		//addPieces();
		
		
	
		
		
		
		
		JLabel name1 = new JLabel(player1.getName(), JLabel.CENTER);
		name1.setBounds(25, 400, 46, 14);
		panel_1.add(name1);
		
		JLabel name2 = new JLabel(player2.getName(), JLabel.CENTER);
		name2.setBounds(606, 400, 46, 14);
		panel_1.add(name2);
		
		for(int i = 0; i<9; i++){
			   red[i].addMouseMotionListener(this); 
			   red[i].addMouseListener(this);
			   blue[i].addMouseMotionListener(this); 
			   blue[i].addMouseListener(this);
		}
		
		for(int i=0; i<16; i++){
			bmills[i]=false;
			rmills[i]=false;
		}
	
	}//end of initialize()

	/**
	 * Just a method that adds all of the empty pieces nodes to the board. 
	 * aslo adds their action listeners 
	 */
	public void addPieces(){
		piece[0] = new JLabel();
		piece[0].setBounds(126, 11, 30, 30);
		panel_1.add(piece[0]);
		
		piece[1] = new JLabel();
		piece[1].setBounds(327, 11, 30, 30);
		panel_1.add(piece[1]);
		
		piece[2] = new JLabel();
		piece[2].setBounds(531, 11, 30, 30);
		panel_1.add(piece[2]);
		
		piece[3] = new JLabel();
		piece[3].setBounds(202,87, 30, 30);
		panel_1.add(piece[3]);
		
		piece[4] = new JLabel();
		piece[4].setBounds(329, 87, 30, 30);
		panel_1.add(piece[4]);
		
		piece[5] = new JLabel();
		piece[5].setBounds(455, 87, 30, 30);
		panel_1.add(piece[5]);
			
		piece[6] = new JLabel();
		piece[6].setBounds(281, 169, 30, 30);
		panel_1.add(piece[6]);
		
		piece[7] = new JLabel();
		piece[7].setBounds(330, 169, 30, 30);
		panel_1.add(piece[7]);
		
		piece[8] = new JLabel();
		piece[8].setBounds(376, 169, 30, 30);
		panel_1.add(piece[8]);
		
		
		piece[9] = new JLabel();
		piece[9].setBounds(126, 215, 30, 30);
		panel_1.add(piece[9]);
		
		piece[10] = new JLabel();
		piece[10].setBounds(202, 215, 30, 30);
		panel_1.add(piece[10]);
		
		piece[11] = new JLabel();
		piece[11].setBounds(281, 215, 30, 30);
		panel_1.add(piece[11]);
	
		piece[12] = new JLabel();
		piece[12].setBounds(376, 215, 30, 30);
		panel_1.add(piece[12]);
		
		piece[13] = new JLabel();
		piece[13].setBounds(455, 215, 30, 30);
		panel_1.add(piece[13]);
		
		piece[14] = new JLabel();
		piece[14].setBounds(531, 215, 30, 30);
		panel_1.add(piece[14]);
		
		piece[15] = new JLabel();
		piece[15].setBounds(281, 261, 30, 30);
		panel_1.add(piece[15]);		
		
		piece[16] = new JLabel();
		piece[16].setBounds(330, 261, 30, 30);
		panel_1.add(piece[16]);
		
		piece[17] = new JLabel();
		piece[17].setBounds(376, 261, 30, 30);
		panel_1.add(piece[17]);		
		
		piece[18] = new JLabel();
		piece[18].setBounds(202, 340, 30, 30);
		panel_1.add(piece[18]);
		
		piece[19] = new JLabel();
		piece[19].setBounds(329, 340, 30, 30);
		panel_1.add(piece[19]);
		
		piece[20] = new JLabel();
		piece[20].setBounds(455, 340, 30, 30);
		panel_1.add(piece[20]);
		
		piece[21] = new JLabel();
		piece[21].setBounds(126, 416, 30, 30);
		panel_1.add(piece[21]);
		
		piece[22] = new JLabel();
		piece[22].setBounds(329, 416, 30, 30);
		panel_1.add(piece[22]);
		
		piece[23] = new JLabel();
		piece[23].setBounds(531, 416, 30, 30);
		panel_1.add(piece[23]);
		
		for(int i = 0; i<piece.length; i++){
			piece[i].addMouseListener(this);
			piece[i].setIcon(null);
			piece[i].setVisible(true);
		}
		
	}
	
	
	/**
	 * method to get names
	 */
	public void getNames(){
		
		String player1Name = null, player2Name = null;
		
		//while(player1Name.equals(null)){
		player1Name=JOptionPane.showInputDialog(null,"Player 1, Enter Name: ?"); 
		//}
		
		player1 = new Player(player1Name);
		
		player2Name=JOptionPane.showInputDialog(null,"Player 2, Enter Name: ?"); 
		
		player2 = new Player(player2Name);
		
	}//end of get name
	
	
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
	    if (drag == true)  
	    { 
	        JComponent jc = (JComponent)e.getSource(); 
	        jc.setLocation(jc.getX()+e.getX(), jc.getY()+e.getY()); 
	    } 


		
	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		 JComponent jc = (JComponent)e.getSource();
		    JLabel j1 = (JLabel) jc;
		    
		    System.out.println("The thing was clicked");

		    
		    if(toRemove == 1){
		    	System.out.println("Here1");
		    	if(j1.getIcon()==(redcircle)){
			    	System.out.println("Here2");
		    		j1.setIcon(null);
		    		checkForNoMills();
		    		redCount--;
		    	}
		    	toRemove = 0;
	    		checkWin();
	    		checkFlying();
		    }
		    
		    if(toRemove == -1){
		    	System.out.println("Here3");
		    	if(j1.getIcon()==(bluecircle)){
			    	System.out.println("Here4");
		    		j1.setIcon(null);
		    		checkForNoMills();
		    		blueCount--;
		    	}
		    	toRemove = 0;
	    		checkWin();
	    		checkFlying();
		    }
		    
		    if(flying){
		    	
		    }
		    
		    
		    
		    if(!placingPiece){   	
		    	System.out.println("Moving piece is false");
		    	
		    	if(blueTurn){
		    		if(jc instanceof JLabel){
					
		    			System.out.println("its a ja label with x coord at " + jc.getX());
		    		if(freeMoving||(count<18 && (jc.getX()) ==636)){
		    			if(j1.getIcon()==(bluecircle)){
		    				placingPiece = true;
							newMovingLabel = j1;
							movingLabel.setIcon(j1.getIcon());
						
		    				System.out.println("The image is blue circle");
						
						//j1.removeMouseListener(null);
			            //j1.setLocation(0, 0);
		    				j1.setIcon(null);
		    			}//end of jc instance if
		    		}
		    		}//end of blue turn if
					
				} else if(!blueTurn){
					if(jc instanceof JLabel){
						if(freeMoving || (count<18 && (jc.getX()) ==21)){
						if(j1.getIcon()==(redcircle)){
							placingPiece = true;
							newMovingLabel = j1;
							movingLabel.setIcon(j1.getIcon());
							//j1.removeMouseListener(null);
				            //j1.setLocation(0, 0);
		    				j1.setIcon(null);
						}
						}
					}
					
				}//end of red turn if

			    }
		    else if(placingPiece) {
		    	if(jc instanceof JLabel){
		    		
		    		if(flying || (checkPlacement((JLabel) jc) && checkMove((JLabel)jc, newMovingLabel))){
		    		((JLabel) jc).setIcon(movingLabel.getIcon());
		    		jc.setVisible(true);
		    		
		    		System.out.println("The check worked");
			    		//This part should go when its one of those blank j Labels    		
			    		//movingLabel.setLocation(jc.getLocation());
			    		//movingLabel.setVisible(true);  		
			    		//blueTurn = !blueTurn;	
			    	//	placingPiece = !placingPiece;
			    		//updateCounter();
		    		
		    			//movePiece((JLabel)jc, movingLabel);
		    	
		    		movingLabel.setIcon(null);
		    		blueTurn = !blueTurn;	
		    		placingPiece = !placingPiece;
		    		updateCounter();
		    			    			    			
		    		checkForNoMills();
		    		mill();
		    		flying = false;
		    		}
		    		
		    		
				}//inf of instace of 
		    
		    	
		    
		    
		    
		    }//end of not moving piece 
		    
		   
		    
		    

		
	}
	
	public void updateCounter(){
		String s1;
		count++;
		if(count == 18){
			freeMoving = true;
		}
		if (count<=9){
   	    	s1="0"+Integer.toString(count);
   	    }
   	    else{
   	    	s1 = Integer.toString(count);
   	    }
            moves.setText(s1);
	}
	
	public void checkFlying(){
		if(redCount==3){
			flying = true;
			JOptionPane.showMessageDialog(this, "Red move 1 piece to anywhere on the board");
		}
		if(blueCount==3){
			flying = true;
			JOptionPane.showMessageDialog(this, "Blue move 1 piece to anywhere on the board");
		}
		
	}
	
	public void checkWin(){
		if(redCount<=2){
			System.out.println(player2.getName());
			JOptionPane.showMessageDialog(this, "Blue Wins!");
			leaderBoard.updateLeaderBoard(player2.getName(), count);
			
			LeaderBoard l2 = new LeaderBoard();
			l2.setVisible(true);
			
			//leaderBoard.setVisible(true);
		}
		
		if(blueCount<=2){
			System.out.println(player1.getName());
			JOptionPane.showMessageDialog(this, "Red Wins!");
			leaderBoard.updateLeaderBoard(player1.getName(), count);
			//leaderBoard.setVisible(true);
			LeaderBoard l2 = new LeaderBoard();
			l2.setVisible(true);
			//
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	
	@Override
	public void mouseReleased(MouseEvent e){
			
		
	}
	
	public boolean checkPlacement(JLabel spot){
		
		boolean legalMove = true;
		
		for(int i=0; i<9; i++){
			if((red[i].getLocation().equals( spot.getLocation())) || (blue[i].getLocation().equals(spot.getLocation()))){
			System.out.println("Invalid Move");
			legalMove = false;
			JOptionPane.showMessageDialog(this, "This place has a piece, please pick a new spot.");
			break;
			}
		}
		
		
		
		
		
		return legalMove;
	}
	
	public void mill (){
		if((piece[0].getIcon()==bluecircle)&&(piece[1].getIcon()==bluecircle)&&(piece[2].getIcon()==bluecircle)&&!bmills[0]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[0]=true;
			toRemove=1;
		}
		
		if((piece[3].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[5].getIcon()==bluecircle)&&!bmills[1]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[1]=true;
			toRemove=1;
		}
		
		if((piece[6].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&(piece[8].getIcon()==bluecircle)&&!bmills[2]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[2]=true;
			toRemove=1;
		} 
		
		if((piece[9].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&!bmills[3]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[3]=true;
			toRemove=1;
		} 
		
		if((piece[12].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&!bmills[4]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[4]=true;
			toRemove=1;
		} 
		
		if((piece[15].getIcon()==bluecircle)&&(piece[16].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle)&&!bmills[5]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[5]=true;
			toRemove=1;
		} 
		
		if((piece[18].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle)&&!bmills[6]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[6]=true;
			toRemove=1;
		} 
		
		if((piece[21].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle)&&!bmills[7]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[7]=true;
			toRemove=1;
		} 
		
		if((piece[0].getIcon()==bluecircle)&&(piece[9].getIcon()==bluecircle)&&(piece[21].getIcon()==bluecircle)&&!bmills[8]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[8]=true;
			toRemove=1;
		}
		
		if((piece[3].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[18].getIcon()==bluecircle)&&!bmills[9]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[9]=true;
			toRemove=1;
		} 
		
		if((piece[6].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&(piece[15].getIcon()==bluecircle)&&!bmills[10]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[10]=true;
			toRemove=1;
		} 
		
		if((piece[1].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&!bmills[11]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[11]=true;
			toRemove=1;
		} 
		
		if((piece[16].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&!bmills[12]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[12]=true;
			toRemove=1;
		} 
		
		if((piece[8].getIcon()==bluecircle)&&(piece[12].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle)&&!bmills[13]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[13]=true;
			toRemove=1;
		} 
		
		if((piece[5].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle)&&!bmills[14]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[14]=true;
			toRemove=1;
		} 
		
		if((piece[2].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle)&&!bmills[15]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[15]=true;
			toRemove=1;
		}
			
		if((piece[0].getIcon()==redcircle)&&(piece[1].getIcon()==redcircle)&&(piece[2].getIcon()==redcircle)&&!rmills[0]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[0]=true;
			toRemove=-1;
		} 
			
		if((piece[3].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[5].getIcon()==redcircle)&&!rmills[1]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[1]=true;
			toRemove=-1;
		}
		
		if((piece[6].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&(piece[8].getIcon()==redcircle)&&!rmills[2]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[2]=true;
			toRemove=-1;
		} 
			
		if((piece[9].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&!rmills[3]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[3]=true;
			toRemove=-1;
		} 
			
		if((piece[12].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&!rmills[4]){
			System.out.println("There is a mill on the top row");	
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[4]=true;
			toRemove=-1;
		} 
			
		if((piece[15].getIcon()==redcircle)&&(piece[16].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle)&&!rmills[5]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[5]=true;
			toRemove=-1;
		} 
		
		if((piece[18].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle)&&!rmills[6]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[6]=true;
			toRemove=-1;
		} 
			
		if((piece[21].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle)&&!rmills[7]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[7]=true;
			toRemove=-1;
		} 
			
		if((piece[0].getIcon()==redcircle)&&(piece[9].getIcon()==redcircle)&&(piece[21].getIcon()==redcircle)&&!rmills[8]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[8]=true;
			toRemove=-1;
		} 
			
		if((piece[3].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[18].getIcon()==redcircle)&&!rmills[9]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[9]=true;
			toRemove=-1;
		}
			
		if((piece[6].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&(piece[15].getIcon()==redcircle)&&!rmills[10]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[10]=true;
			toRemove=-1;
		} 
		
		if((piece[1].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&!rmills[11]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[11]=true;
			toRemove=-1;
		} 
			
		if((piece[16].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&!rmills[12]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[12]=true;
			toRemove=-1;
		} 
			
		if((piece[8].getIcon()==redcircle)&&(piece[12].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle)&&!rmills[13]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[13]=true;
			toRemove=-1;
		} 
			
		if((piece[5].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle)&&!rmills[14]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[14]=true;
			toRemove=-1;
		} 
		
		if((piece[2].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle)&&!rmills[15]){
			System.out.println("There is a mill on the top row");
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[15]=true;
			toRemove=-1;
		} 
	}
	
	public void checkForNoMills(){
		
		if(!((piece[0].getIcon()==bluecircle)&&(piece[1].getIcon()==bluecircle)&&(piece[2].getIcon()==bluecircle))){
			bmills[0]=false;
		}
		
		if(!((piece[3].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[5].getIcon()==bluecircle))){
			bmills[1]=false;
		}
		
		if(!((piece[6].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&(piece[8].getIcon()==bluecircle))){
			bmills[2]=false;
		} 
		
		if(!((piece[9].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle))){
			bmills[3]=false;
		} 
		
		if(!((piece[12].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle))){
			bmills[4]=false;
		} 
		
		if(!((piece[15].getIcon()==bluecircle)&&(piece[16].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle))){
			bmills[5]=false;
		} 
		
		if(!((piece[18].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle))){
			bmills[6]=false;
		} 
		
		if(!((piece[21].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle))){
			bmills[7]=false;
		} 
		
		if(!((piece[0].getIcon()==bluecircle)&&(piece[9].getIcon()==bluecircle)&&(piece[21].getIcon()==bluecircle))){
			bmills[8]=false;
		}
		
		if(!((piece[3].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[18].getIcon()==bluecircle))){
			bmills[9]=false;
		} 
		
		if(!((piece[6].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&(piece[15].getIcon()==bluecircle))){
			bmills[10]=false;
		} 
		
		if(!((piece[1].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle))){
			bmills[11]=false;
		} 
		
		if(!((piece[16].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle))){
			bmills[12]=false;
		} 
		
		if(!((piece[8].getIcon()==bluecircle)&&(piece[12].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle))){
			bmills[13]=false;
		} 
		
		if(!((piece[5].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle))){
			bmills[14]=false;
		} 
		
		if(!((piece[2].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle))){
			bmills[15]=false;
		}
			
		if(!((piece[0].getIcon()==redcircle)&&(piece[1].getIcon()==redcircle)&&(piece[2].getIcon()==redcircle))){
			rmills[0]=false;
		} 
			
		if(!((piece[3].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[5].getIcon()==redcircle))){
			rmills[1]=false;
		}
		
		if(!((piece[6].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&(piece[8].getIcon()==redcircle))){
			rmills[2]=false;
		} 
			
		if(!((piece[9].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle))){;
			rmills[3]=false;
		} 
			
		if(!((piece[12].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle))){
			rmills[4]=false;
		} 
			
		if(!((piece[15].getIcon()==redcircle)&&(piece[16].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle))){
			rmills[5]=false;
		} 
		
		if(!((piece[18].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle))){
			rmills[6]=false;
		} 
			
		if(!((piece[21].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle))){
			rmills[7]=false;
		} 
			
		if(!((piece[0].getIcon()==redcircle)&&(piece[9].getIcon()==redcircle)&&(piece[21].getIcon()==redcircle))){
			rmills[8]=false;
		} 
			
		if(!((piece[3].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[18].getIcon()==redcircle))){
			rmills[9]=false;
		}
			
		if(!((piece[6].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&(piece[15].getIcon()==redcircle))){
			rmills[10]=false;
		} 
		
		if(!((piece[1].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle))){
			rmills[11]=false;
		} 
			
		if(!((piece[16].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle))){
			rmills[12]=false;
		} 
			
		if(!((piece[8].getIcon()==redcircle)&&(piece[12].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle))){
			rmills[13]=false;
		} 
			
		if(!((piece[5].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle))){
			rmills[14]=false;
		} 
		
		if(!((piece[2].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle))){;
			rmills[15]=false;
		}
		
		
	}
	
	public void removePiece(int toRemove){
		if(toRemove ==1){
			
		} else {
			
		}
	}

	
	
	/**
	 * This should check to make sure the pieces are not moving 
	 * should just cycle through and make sure that 
	 */
	
	 /**
     * This should check to make sure the pieces are not moving 
     * should just cycle through and make sure that 
     */
    
    public boolean checkMove(JLabel newLocation, JLabel oldLocation){
        if (!freeMoving)
            return true;
        else if( areAdjacent(newLocation, oldLocation) ){

            System.out.println("THE ADJACENT THING WORKED");
            
            return true;
        }
/*
        else if(newLocation.getX() == oldLocation.getX()  ) {
            System.out.println("Allow the x axis move");
            return true;
            //movePiece(newLocation, oldLocation);
            
        }
        else if(newLocation.getY() == oldLocation.getY()) {
            System.out.println("Allow the Y axis move");
            return true;
            //movePiece(newLocation, oldLocation);
            
            
        }
*/        
        
        else{
            System.out.println("DO NOT ALLOW MOVE!!!!!!");
            
            JOptionPane.showMessageDialog(this, "I cant let you do that Dave");
            //oldLocation.setVisible(true);
            return false;
            
    
        
        }
        
    }//end of the method
    
    
    /**
     * I needed a method to make sure that the points are adjacent and thus can be moved between. 
     * It takes in the two points and through a convuluted if else stuff finds out if they are adjacent.
     * this seemed like the most straight forward way to do it 
     */
    public boolean areAdjacent(JLabel oldLocation, JLabel newLocation){
        
    	System.out.println("Locaition 1: "+oldLocation.getLocation());
    	System.out.println("Loc   2: "+newLocation.getLocation());
    	
        //pt 0 and 1 are adjacent
        if( 
                ( oldLocation.getLocation().equals( piece[0].getLocation() )  &&
                  newLocation.getLocation().equals( piece[1].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[1]. getLocation())  &&
                  newLocation.getLocation().equals( piece[0].getLocation()   )
                  )
                
        
            )    return true;
        //if 1 and 2 are adjacent etc...
        else if( 
                ( oldLocation.getLocation().equals( piece[1].getLocation() )  &&
                  newLocation.getLocation().equals( piece[2].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[2]. getLocation())  &&
                  newLocation.getLocation().equals( piece[1].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[3].getLocation() )  &&
                  newLocation.getLocation().equals( piece[4].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[4]. getLocation())  &&
                  newLocation.getLocation().equals( piece[3].getLocation()  ) )
                
                )return true;        
        else if( 
                ( oldLocation.getLocation().equals( piece[4].getLocation() )  &&
                  newLocation.getLocation().equals( piece[5].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[5]. getLocation())  &&
                  newLocation.getLocation().equals( piece[4].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[6].getLocation() )  &&
                  newLocation.getLocation().equals( piece[7].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[7]. getLocation())  &&
                  newLocation.getLocation().equals( piece[6].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[7].getLocation() )  &&
                  newLocation.getLocation().equals( piece[8].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[8]. getLocation())  &&
                  newLocation.getLocation().equals( piece[7].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[9].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[9].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[11].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[11].getLocation()  ) )
                
                )return true;
        
        else if( 
                ( oldLocation.getLocation().equals( piece[12].getLocation() )  &&
                  newLocation.getLocation().equals( piece[13].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[13]. getLocation())  &&
                  newLocation.getLocation().equals( piece[12].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[13].getLocation() )  &&
                  newLocation.getLocation().equals( piece[14].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[14]. getLocation())  &&
                  newLocation.getLocation().equals( piece[13].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[15].getLocation() )  &&
                  newLocation.getLocation().equals( piece[16].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[16]. getLocation())  &&
                  newLocation.getLocation().equals( piece[15].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[16].getLocation() )  &&
                  newLocation.getLocation().equals( piece[17].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[17]. getLocation())  &&
                  newLocation.getLocation().equals( piece[16].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[18].getLocation() )  &&
                  newLocation.getLocation().equals( piece[19].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[19]. getLocation())  &&
                  newLocation.getLocation().equals( piece[18].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[19].getLocation() )  &&
                  newLocation.getLocation().equals( piece[20].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[20]. getLocation())  &&
                  newLocation.getLocation().equals( piece[19].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[21].getLocation() )  &&
                  newLocation.getLocation().equals( piece[22].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[22]. getLocation())  &&
                  newLocation.getLocation().equals( piece[21].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[22].getLocation() )  &&
                  newLocation.getLocation().equals( piece[23].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[23]. getLocation())  &&
                  newLocation.getLocation().equals( piece[22].getLocation()  ) )
                
                )return true;
        //*****
        //START OF VERTICLE LINES::!~~~!~!~!~!
        //****     ||        |       |         | 
        else if( 
                ( oldLocation.getLocation().equals( piece[0].getLocation() )  &&
                  newLocation.getLocation().equals( piece[9].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[9]. getLocation())  &&
                  newLocation.getLocation().equals( piece[0].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[9].getLocation() )  &&
                  newLocation.getLocation().equals( piece[21].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[21]. getLocation())  &&
                  newLocation.getLocation().equals( piece[9].getLocation()  ) )
                
                )return true;
        
        else if( 
                ( oldLocation.getLocation().equals( piece[3].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[3].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[10].getLocation() )  &&
                  newLocation.getLocation().equals( piece[18].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[18]. getLocation())  &&
                  newLocation.getLocation().equals( piece[10].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[6].getLocation() )  &&
                  newLocation.getLocation().equals( piece[11].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[11]. getLocation())  &&
                  newLocation.getLocation().equals( piece[6].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[11].getLocation() )  &&
                  newLocation.getLocation().equals( piece[15].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[15]. getLocation())  &&
                  newLocation.getLocation().equals( piece[11].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[1].getLocation() )  &&
                  newLocation.getLocation().equals( piece[4].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[4]. getLocation())  &&
                  newLocation.getLocation().equals( piece[1].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[4].getLocation() )  &&
                  newLocation.getLocation().equals( piece[7].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[7]. getLocation())  &&
                  newLocation.getLocation().equals( piece[4].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[16].getLocation() )  &&
                  newLocation.getLocation().equals( piece[19].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[19]. getLocation())  &&
                  newLocation.getLocation().equals( piece[16].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[19].getLocation() )  &&
                  newLocation.getLocation().equals( piece[22].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[22]. getLocation())  &&
                  newLocation.getLocation().equals( piece[19].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[8].getLocation() )  &&
                  newLocation.getLocation().equals( piece[12].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[12]. getLocation())  &&
                  newLocation.getLocation().equals( piece[8].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[12].getLocation() )  &&
                  newLocation.getLocation().equals( piece[17].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[17]. getLocation())  &&
                  newLocation.getLocation().equals( piece[12].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[5].getLocation() )  &&
                  newLocation.getLocation().equals( piece[13].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[13]. getLocation())  &&
                  newLocation.getLocation().equals( piece[5].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[13].getLocation() )  &&
                  newLocation.getLocation().equals( piece[20].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[20]. getLocation())  &&
                  newLocation.getLocation().equals( piece[13].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[14].getLocation() )  &&
                  newLocation.getLocation().equals( piece[2].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[2]. getLocation())  &&
                  newLocation.getLocation().equals( piece[14].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[14].getLocation() )  &&
                  newLocation.getLocation().equals( piece[23].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[23]. getLocation())  &&
                  newLocation.getLocation().equals( piece[13].getLocation()  ) )
                
                )return true;
        
        
        else

            return false;
        
    }
	
	
	/**
	 * move a piece on the game board after all other chcks have been done
	 */
	public void movePiece(JLabel newLocation, JLabel oldLocation){

		oldLocation.setLocation(newLocation.getLocation());
//		oldLocation.setVisible(true);  		
//		blueTurn = !blueTurn;	
//		placingPiece = !placingPiece;
//		updateCounter();
		movingLabel.setIcon(null);
		blueTurn = !blueTurn;	
		placingPiece = !placingPiece;
		updateCounter();
	}
	
	
	
	
    public void checkMills(){
    	//Row
    	for(a = 0; a<7; a++){
    		totalSum = 0;
    		for(int b = 0; b < 7; b++){
    			if(a != 3){
    			  totalSum = totalSum +board[a][b];
    			  
    			}
    		}
    		
    		if(a == 3){
        		for(b = 0; b < 3; b++){
        			totalSum = totalSum +board[a][b];
        			
        			
        		}
    		}
        		if(totalSum == 3){
            		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
            		isMill = true;
            	}
            	if(totalSum == -3){
            		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
            		isMill = true;
            	}
    	}
    	
            a = 3;
            totalSum  = 0;
    		for(b = 4; b < 7; b++){
    			totalSum = totalSum +board[a][b];		
    		}
    	
    	if(totalSum == 3){
    		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
    		isMill = true;
    	}
    	if(totalSum == -3){
    		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
    		isMill = true;
    	}
    	
    	//column
    	for(a = 0; a<7; a++){
		   totalSum = 0;
		   for(int b = 0; b < 7; b++){
			  if(a != 3){
			     totalSum = totalSum +board[b][a];
			}
		}
		
		  if(a == 3){
    		  for(b = 0; b < 3; b++){
    			 totalSum = totalSum +board[b][a];
    			
    		  }
		  }
    		
		  if(totalSum == 3){
        		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
        		isMill = true;
        	}
        	if(totalSum == -3){
        		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");	
        		isMill = true;
        	}
	}
	
        a = 3;
        totalSum  = 0;
		for(b = 4; b < 7; b++){
			totalSum = totalSum +board[b][a];		
		}
	
	if(totalSum == 3){
		JOptionPane.showMessageDialog(this, "Blue reaches the Mill, take away a red piece!");	
		isMill = true;
	}
	if(totalSum == -3){
		JOptionPane.showMessageDialog(this, "Red reaches the Mill, take away a blue piece!");
		isMill = true;
	}
}
}